﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

//using LZQXT.Test.Forms;

using Pub;
using LZQXT.Test.Forms;
using LZQXT.Test.Forms.Encrypt;
using LZQXT.Test.Forms.Cmd;
using LZQXT.Test.Forms.PE;
using LZQXT.Test.Forms.Reg;
using Script;
using JT_Regular;
using JT_QRCode;
using System.Management;
using System.IO;
//using Script;
//using LZQXT.Test.Forms.DB;
//using LZQXT.Test.Forms.Reg;
//using LZQXT.Test.Forms.Cmd;
//using LZQXT.Test.Forms.Script;
//using LZQXT.Test.Forms.Tree;
//using LZQXT.Test.Forms.PE;
//using LZQXT.Test.Forms.Encrypt;

namespace LZQXT.Test
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        /// 

        public static FMain fmain;

        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            checkSQLite();

            ADOTest ado1 = new ADOTest();
            //CPub.webPath = ado1.sel1("select * from G_Pub_Mcb where use_note='WebPath'").Tables[0].Rows[0]["Val_Str"].ToString();
            CPub.exePath = Application.StartupPath;
            CPub.B_Test = Boolean.Parse(CConfig.getPermite("Test"));

            fmain = new FMain();

            fmain.flst.Add(new FDBTree_lzqx());
            fmain.flst.Add(new FDBTree());      //树菜单管理
            fmain.flst.Add(new FDBMgr());       //数据库管理
            fmain.flst.Add(new FEnMain());      //字符串加解密
            fmain.flst.Add(new F_Regular());    //正则表达是
            fmain.flst.Add(new FClsView());     //类查看
            fmain.flst.Add(new FScript());      //脚本执行
            fmain.flst.Add(new FQRCode());      //生成二维码
            fmain.flst.Add(new FPEMain());      //pe结构查看
            fmain.flst.Add(new FReg());         //环境变量查看
            fmain.flst.Add(new FCmd());         //命令行


            Application.Run(fmain);
        }

        private static void checkSQLite() {
            string dll32 = System.Windows.Forms.Application.StartupPath + "\\lib\\SQLite32.DLL";
            string dll64 = System.Windows.Forms.Application.StartupPath + "\\lib\\SQLite64.DLL";
            string dllpath = System.Windows.Forms.Application.StartupPath + "\\System.Data.SQLite.dll";
            if (Detect32or64() == "32")
            {
                // do 32bit things.
                try
                {
                    using (FileStream fs = File.Create(dllpath)) { }
                    File.Copy(dll32, dllpath, true);
                }

                catch
                {
                    Console.WriteLine("ERR");
                }

            }
            else if (Detect32or64() == "64")
            {
                //do 64bit things
                try
                {
                    using (FileStream fs = File.Create(dllpath)) { }
                    File.Copy(dll64, dllpath, true);
                }

                catch
                {
                    Console.WriteLine("ERR");
                }
            }
        }

        private static string Detect32or64()
        {
            try
            {
                string addressWidth = String.Empty;
                ConnectionOptions mConnOption = new ConnectionOptions();
                ManagementScope mMs = new ManagementScope("\\\\localhost", mConnOption);
                ObjectQuery mQuery = new ObjectQuery("select AddressWidth from Win32_Processor");
                ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(mMs, mQuery);
                ManagementObjectCollection mObjectCollection = mSearcher.Get();
                foreach (ManagementObject mObject in mObjectCollection)
                {
                    addressWidth = mObject["AddressWidth"].ToString();
                }
                return addressWidth;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return String.Empty;
            }
        }
    }
}